package com.base;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


public abstract class BaseController<T> {

    /**
     * 获取session中的用户信息
     *
     * @return
     */
    @SuppressWarnings("unchecked")
//    protected T getUserInfoInSession() {
//        T t = (T) getSession().getAttribute(SessionKey.USER_INFO.name());
//        return t;
//    }

    /**
     * 获取request
     *
     * @return
     */
    protected HttpServletRequest getRequest() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        return request;
    }

    /**
     * 获取session
     *
     * @return
     */
    protected HttpSession getSession() {
        return getRequest().getSession();
    }
}
